Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

338
Vistas
ValidationError: validTill: Cast to Number failed for value \"NaN\" at path \"validTill\"

I can't seem to get my POST api to work when it was working normally like 1 week ago, I think I forgot how to put the date but here is the error: ValidationError: validTill: Cast to Number failed for value \"NaN\" at path \"validTill\" Here is my json I am trying to send: {"plrID": "1", "key": "abc", "validTill": "1633872004841", "reason": "test"} is there something I am doing wrong here? I have tried doing it with a date but it didn't work. Here is the code for it: ```const mongoose = require('mongoose') module.exports = async function (req, res) { const receivedData = {...req.body}

try {
    require('../models/Ban')
    const BanModel = mongoose.model('Ban')

    const pre = await BanModel.findOne({ plrID: receivedData.plrID})

    if (pre) {
        var someDate = new Date();
        var numberOfDaysToAdd = receivedData.validDays;
        someDate.setDate(someDate.getDate() + numberOfDaysToAdd);
    
        await BanModel.findByIdAndUpdate(pre._id, {$set: { validTill: someDate.getTime(), Valid: true }})
    } else {
        var someDate = new Date();
        var numberOfDaysToAdd = receivedData.validDays;
        someDate.setDate(someDate.getDate() + numberOfDaysToAdd);

        const newBanInstance = new BanModel({
            plrID: receivedData.plrID,
            key: receivedData.key,
            validTill: someDate.getTime(),
            reason: receivedData.reason,
            gameID: 1,
            Cancelled: false,
            Valid: true
        })

        const newSub = await newBanInstance.save()

        require('../models/BanCreator')
        const creatorModel = mongoose.model('BanCreator')

        await creatorModel.findOneAndUpdate({ gameID: 1 },  { $push: { BanIds: newSub._id } })
    }

    var nowDate = new Date();
    var addDays = receivedData.validDays;
    nowDate.setDate(nowDate.getDate() + addDays);

    res.json({
        plrID: receivedData.plrID,
        validTill: nowDate.toDateString(),
        reason: receivedData.reason,
        valid: true,
        failResponse: "Faced No Errors"
    })
} catch (e) {
    res.json({
        plrID: receivedData.plrID,
        validTill: null,
        reason: receivedData.reason,
        valid: false,
        failResponse: `oopsies an error happened: ${e}`
    })
}

}``` Thanks! Ben

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I did the incorrect params, I ended up fixing it myself.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda